<?php

/**
 * Pes for PHP 5.3+
 *
 * Copyright (c) 2013 phpeskill.com (http://www.phperskill.com)
 *
 * For the full copyright and license information, please view
 * the file LICENSE.md that was distributed with this source code.
 */

namespace Expand;

use Core\Db\Db as Db;

/**
 * PES前台标签模块
 * 本标签功能，均采用弱处理模式
 * 除非执行的语句存在致命错误，
 * 否则程序不进行任何错误警告！
 * @author LazyPHP
 * @version 1.0
 */
class Label {

    /**
     * 初始化数据库
     * @param str $name 表名
     * @return obj 返回数据库对象
     */
    private static function db($name) {
        $db = Db::__init();
        $db->tableName($name);
        return $db;
    }

    /**
     * 执行查询的标签
     * @return array 返回二维数组
     */
    public static function exec($sql, $param = '') {
        $db = Db::__init();
        $result = $db->query($sql, $param);
        if(empty($result)){
            return array();
        }
        return $result;
    }

    /**
     * 根据父类ID查找数据
     * @param type $parent_id 分类父类ID
     * @param type $is_nav 是否为导航
     * @return array 返回二维数组
     */
    public static function getCate($parent_id = '0', $is_nav =''){
        $db = self::db('category');
        $where = 'parent_id = :parent_id';
        if(!empty($is_nav)){
            $where .= ' and is_nav = 1';
        }
        $data['parent_id'] = $parent_id;
        $result = $db->where($where)->order('listsort asc, id asc')->select($data);
        return $result;
    }
    
    /**
     * 根据模型名称，获取内容
     * @param type $model 模型名称
     * @return array 返回二维数组
     */
    public static function getModel($model){
        $db = self::db($model);
        $result = $db->select();
        return $result;
    }
    
    /**
     * 单页标签
     */
    public static function page($id){
        $db = self::db('page');
        $result = $db->where('id = :id')->find(array('id'=>$id));
        return $result;
    }
    
    /**
     * 幻灯片
     */
    public static function slideShow($slideshow_type_id, $limit = '99'){
        $db = self::db('slideshow');
        $result = $db->where('slideshow_type_id = :slideshow_type_id')->order('listsort asc, slideshow_id desc')->limit($limit)->select(array('slideshow_type_id'=>$slideshow_type_id));
        return $result;
    }

}